		TITLE	SOFTPENT - Copyright (C) 1994 SLR Systems

		INCLUDE	MACROS
		INCLUDE	CDDATA

		PUBLIC	INSTALL_SOFT_PENT

;
;		DS:SI (CX) IS SYMBOL TO BE ADDED TO LIST OF COMDAT SOFT REFERENCES
;

		.DATA

		EXTERNDEF	MYCOMDAT_LINDEX:DWORD


		.CODE	PASS1_TEXT

		EXTERNDEF	ALLOC_LOCAL:PROC


INSTALL_SOFT_PENT	PROC
		;
		;EAX IS PENT_GINDEX TO ADD TO LIST OF PENTS REFERENCED BY THIS COMDAT...
		;
		PUSH	ESI
		MOV	ESI,EAX

		MOV	EAX,MYCOMDAT_LINDEX		;LATEST COMDAT REFERENCED
		CONVERT_MYCOMDAT_EAX_ECX

		PUSH	EBX
		MOV	EBX,ECX

		MOV	EDX,ESI
		LEA	ESI,[ECX].MYCOMDAT_STRUCT._MCD_FIRST_SOFT_PENT_BLOCK

		XOR	ECX,ECX
L1$:
		MOV	EAX,[ESI]

		TEST	EAX,EAX				;NEXT BLOCK EXISTS?
		JZ	L8$				;NOPE, GO CREATE IT

		MOV	ECX,[EAX]			;SCAN FOR MATCHING SYMBOL
		LEA	ESI,[EAX+4]

		MOV	EBX,ECX
L2$:
		MOV	EAX,[ESI]
		ADD	ESI,8

		CMP	EAX,EDX
		JZ	L9$				;JUMP IF MATCH

		DEC	ECX
		JNZ	L2$

		CMP	EBX,SOFT_PER_BLK
		JZ	L1$
		;
		;ROOM FOR ANOTHER, STORE IT
		;
		LEA	EAX,[EBX*8]
		MOV	[ESI],EDX

		MOV	[ESI+4],ECX
		SUB	ESI,EAX

		INC	EBX

		MOV	[ESI-4],EBX

		POPM	EBX,ESI

		RET

L9$:
		INC	DPTR [ESI-4]
		POPM	EBX,ESI

		RET


L8$:
		;
		;CREATE NEW BLOCK, ES:DI GETS POINTER, DX
		;
		MOV	EAX,SOFT_PER_BLK*8+8
		CALL	ALLOC_LOCAL

		PUSH	EDI
		MOV	[ESI],EAX

		LEA	EDI,[EAX+8]
		MOV	DPTR [EAX],1

		MOV	DPTR [EAX+4],EDX
		MOV	ECX,(SOFT_PER_BLK*8+8-8)/4

		XOR	EAX,EAX

		REP	STOSD

		POPM	EDI,EBX,ESI

		RET

INSTALL_SOFT_PENT	ENDP


		END

